import axios from './http';
import { HttpResponse } from '../types/HttpResponse';

interface Url {
  [key: string]: string;
}
const url: Url = {
  getCount: '/users/count',
  postEx: '/ex/post',
  optimize: '/optimize',
  analyze: '/analyze',
  search: '/search'
};

//封装接口方法
export class Example {
  //get example
  static async getCount(): Promise<HttpResponse> {
    return axios(url.getCount, {
      method: 'get',
      responseType: 'json',
    });
  }

  // 矩阵优化后端接口
  static async opt(params:{
    matrixStr:string,
    type:string
  }): Promise<HttpResponse> {
    return axios(url.optimize, {
      method: 'get',
      responseType: 'json',
      params,
    });
  }
  // 矩阵性质分析后端接口
  static async analyze(params:{
    m_in:string,
    input_type:string
  }): Promise<HttpResponse> {
    return axios(url.analyze, {
      method: 'get',
      responseType:'json',
      params,
    });
  }
  // 矩阵搜索后端接口
  static async search(params:{
    method:number,
    type:number
  }): Promise<HttpResponse> {
    return axios(url.search, {
      method: 'post',
      responseType:'json',
      params,
    });
  }

  //post example
  static async postEx(data: { 
    id: number }): Promise<HttpResponse> {
    return axios(url.postEx, {
      method: 'post',
      responseType: 'json',
      data: data,
    });
  }
}
